// 入驻申请
<template>
   <div class="search">
     <Row>
        <Card>
          <Row class="operation">
            <Form inline :label-width="100" ref="searchForm" :model="searchForm" label-position="right">
              <Button @click="handleSearch" icon="md-refresh">刷新</Button>
              <FormItem label="商品名称" prop="goodName">
                <Input type="text" v-model="searchForm.goodName" placeholder="请输入商品名称"/>
              </FormItem>
              <FormItem label="订单方式" prop="orderStatus">
                <Select v-model="searchForm.orderStatus" style="width:200%" clearable>
                  <Option value="PRE_PAY">待付款</Option>
                  <Option value="PRE_SEND">待发货</Option>
                  <Option value="DELIVER_SEND">待收货</Option>
                  <Option value="PRE_COMMENT">待评价</Option>
                  <Option value="SALE_AFTER">退款售后</Option>
                  <Option value="CANCEL_ORDER">取消订单</Option>
                  <Option value="IS_COMPLETE">完成订单</Option>
                  <Option value="RETURN_FINISH">退款完成</Option>
                </Select>
              </FormItem>
              <Button @click="handleSearch" type="primary" icon="ios-search" style="margin-left:20px;">搜索</Button>
            </Form>
          </Row>
          <Modal title="查看大图" v-model="visible" class-name="fl-image-modal">
            <img :src="imgUrl" style="width: 100%">
          </Modal>

          <Row>
            <Table :loading="loading" border :columns="columns" :data="data" ref="table" sortable="custom" @on-sort-change="changeSort"></Table>
          </Row>

          <Row type="flex" justify="end" class="page">
            <Page :current="searchForm.pageNumber" :total="total" :page-size="searchForm.pageSize" @on-change="changePage" @on-page-size-change="changePageSize" :page-size-opts="[10,20,50]" size="small" show-total show-elevator show-sizer></Page>
          </Row>
        </Card>
     </Row>

     <Modal :title="modalTitle" v-model="commentVisible" :mask-closable='false' :width="600">
      <Form ref="commentForm" :model="commentForm" :label-width="100" :rules="formValidate" >
        <FormItem label="快递单号" prop="expressCode">
          <Input type="text" v-model="commentForm.expressCode" placeholder="请输入快递单号" />
        </FormItem>
      </Form>
      <div slot="footer">
        <Button type="text" @click="commentVisible=false">取消</Button>
        <Button type="primary" :loading="submitLoading" @click="handleSubmit">提交</Button>
      </div>
    </Modal>

    <Modal :title="modalTitle" v-model="detailVisible" :mask-closable='false' :width="800">
      <div style="padding: 10px 0;font-size: 16px;"><label>购买人：</label>{{goodsDetail.consignee}}</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>购买人联系方式：</label>{{goodsDetail.phone}}</div>
      <!-- <div style="padding: 10px 0;font-size: 16px;"><label>收货地址：</label>{{goodsDetail.address}}</div> -->
      <div style="padding: 10px 0;font-size: 16px;"><label>商品单价：</label>{{goodsDetail.goodNewPrice}}元</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>购买数量：</label>{{goodsDetail.buyCount}}</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>购买规格：</label>{{goodsDetail.attrSymbolPathName}}</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>优惠金额：</label>{{goodsDetail.subtractMoney}}元</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>实付金额：</label>{{goodsDetail.totalPrice}}元</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>所得积分：</label>{{goodsDetail.integral}}</div>
      <div style="padding: 10px 0;font-size: 16px;"><label>购买时间：</label>{{goodsDetail.createTime}}</div>
    </Modal>
   </div> 
</template>

<script>
export default {
  data(){
    return{ 
      submitLoading: false,
      visible:false,
      detailVisible: false,
      total:0,
      modalTitle: "",
      loading: true, // 表单加载状态
      data:[],//表单数据
      searchForm:{
        goodName:'',
        // payTypeEnum:'',
        commonConstant: "个人商家",
        pageSize:10,
        pageNumber:1,
        orderStatus: ""
      },
      commentForm: {
        id: "",
        orderStatus: "DELIVER_SEND",
        expressCode: ""
      },
      commentVisible: false,
      formValidate: {
        expressCode: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
      columns: [
      // 表头
      {
        type: "index",
        width: 60,
        align: "center"
      },
      {
        title: "订单编号",
        key: "orderNum",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "商品名称",
        key: "goodName",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "店家名称",
        key: "shopName",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "商品图片",
        key: "goodPics",
        minWidth: 120,
        sortable: false,
        render: (h, params) => {
          return h("img", {
            style:{
              width:'60px',
              height:'40px',
            },
            attrs:{
              src:params.row.goodPics,
            },
            on:{
              click:(e)=>{
                console.log(e)
                this.handleView(e.srcElement.currentSrc)
              }
            }
          });
        }
      },
      {
        title: "购买人",
        key: "consignee",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "订单状态",
        key: "orderStatus",
        minWidth: 120,
        sortable: false,
      },
      {
        title: "创建时间",
        key: "createTime",
        minWidth: 120,
        sortable: false,
      },
      {
          title: "操作",
          width: 260,
          align: "center",
          fixed: "right",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.detail(params.row);
                    }
                  }
                },
                "详情"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "info",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px",
                    display:(params.row.orderStatus=='待发货')?"inline-block":"none"
                  },
                  on: {
                    click: () => {
                      this.deliverGoods(params.row);
                    }
                  }
                },
                "发货"
              ),
            ]);
          }
        }
      ],
      goodsDetail: {},
      }
    },
    methods:{
      init(){
        this.getDataList()
      },
      handleView(url) {
        this.imgUrl = url;
        this.visible = true;
      },
      getDataList(){
        if (this.searchForm.orderStatus === undefined) {
          this.searchForm.orderStatus = ""
        }
        this.loading = true;
        this.postRequest("/order/PCgetShopOrderList",this.searchForm).then(res =>{
          this.loading = false
          if(res.success){
            this.data = res.result.data;
            this.total = res.result.size;
          }
        })
      },
      //搜索查询
      handleSearch(){
        this.searchForm.pageNumber = 1;
        // this.searchForm.pageSize = 10;
        this.getDataList()
      },
      changeSort(e) {
        this.searchForm.sort = e.key;
        this.searchForm.order = e.order;
        if (e.order === "normal") {
          this.searchForm.order = "";
        }
        this.getDataList();
      },
      changePage(v) {
        this.searchForm.pageNumber = v;
        this.getDataList();
      },
      changePageSize(v) {
        this.searchForm.pageSize = v;
        this.getDataList();
      },
      clearSelectAll(){
        this.$refs.searchForm.resetFields()
        this.getDataList()
      },
      // 发货
      deliverGoods (v) {
        this.modalTitle = "发货";
        this.commentForm.expressCode = ""
        this.commentForm.id = v.id;
        this.commentVisible = true;
      },
      handleSubmit () {

        this.$refs.commentForm.validate(valid=> {
          if (valid) {
            this.submitLoading = true;
            this.postRequest("/order/changeStatus",this.commentForm).then(res=> {
              this.submitLoading = false
              if (res.success) {
                this.$Message.success("发货成功");
                this.getDataList();
                this.commentVisible = false;
              } else {
                this.$Message.success(res.message);
                this.getDataList();
                this.commentVisible = false;
              }
            })
          }
        })
      },
      // 订单详情 
      detail (v) {
        this.modalTitle = "商品详情";
        this.goodsDetail = v;
        this.detailVisible = true;
      }
    },
    mounted(){
      this.init()
    }
}
</script>

<style lang="less">
.search {
    .operation {
        margin-bottom: 2vh;
    }
    .select-count {
        font-size: 13px;
        font-weight: 600;  
        color: #40a9ff;
    }
    .select-clear {
        margin-left: 10px;
    }
    .page {
        margin-top: 2vh;
    }
    .drop-down {
        font-size: 13px;
        margin-left: 5px;
    }
}
</style>